Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

993
Visualizações
"EC2 Metadata roleName request returned error" using aws encryption library with NestJS

I am trying to use aws encryption sdk in a NestJS application, the next code source shows the implementation.

import { Controller, Get } from '@nestjs/common';
import {KmsKeyringNode, encrypt} from '@aws-crypto/client-node'


@Controller('encryption')
export class EncryptionController {
  // constructor() {}
  @Get()
  async crypt() {
    const generatorKeyId = "generatior key";
    const masterKeyId = "master key id";
    const keyring = new KmsKeyringNode({keyIds:[masterKeyId], generatorKeyId: generatorKeyId});
    const plainText = "My passwords for senstive data";
    const context = {
      accountId: "100",
      purpose: "youtube demo",
      country: "Sri Lanka"
    };
    const { result } = await encrypt(keyring, plainText, { encryptionContext: context });
    console.log(result)


  }

}

but when I execute a request to see the result of my implementation I receive the next error

Error: connect EHOSTUNREACH 169.254.169.254:80
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1128:14) {
    message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
    errno: 'EHOSTUNREACH',
    code: 'CredentialsError',
    syscall: 'connect',
    address: '169.254.169.254',
    port: 80,
    time: 2020-06-09T11:41:47.638Z,
    originalError: {
      message: 'Could not load credentials from any providers',
      errno: 'EHOSTUNREACH',
      code: 'CredentialsError',
      syscall: 'connect',
      address: '169.254.169.254',
      port: 80,
      time: 2020-06-09T11:41:47.638Z,
      originalError: {
        message: 'EC2 Metadata roleName request returned error',
        errno: 'EHOSTUNREACH',
        code: 'EHOSTUNREACH',
        syscall: 'connect',
        address: '169.254.169.254',
        port: 80,
        time: 2020-06-09T11:41:47.637Z,
        originalError: [Object]
      }
    }
  }

However I copy a nodejs script from this tutorial to see if it works with my aws sdk set up and I did not receive any error, also if a execute aws kms encryption methods in the cli I hadn't any error.

I tried to export AWS_SDK_LOAD_CONFIG=1 variable how I saw in other similar errors.

Does anyone know what's going on?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I had the same problem. It cost me quite some head ache because I had this running in AWS Fargate and debugging is not that easy there.

The error means the Javascript SDK can not find the AWS credentials. Here you can see in what order the SDK tries to load the credentials from: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html

My error was quite embarrassing, I just had a typo in my environment variables. My variable was AWS_ACCESSS_KEY_ID instead of AWS_ACCESS_KEY_ID. (Quite hard to see the difference, right?)

So probably double check the names of your environment variables (or config files)

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda